package com.itheima.patterns.behaviorpattern.interpreter;

//加法表达式类
public class Plus extends AbstractExpression{
    
    //+左边的表达式
    private AbstractExpression left;
    //+右边的表达式
    private AbstractExpression right;
    
    public Plus(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }
    
    @Override
    public int interpret(Context context) {
        //将左边表达式的结果和右边的进行相加  2+3
        return left.interpret(context) + right.interpret(context);
    }
    
    @Override
    public String toString() {
        return "(" + left.toString() + "+" + right.toString() + ")";
    }
}